<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-button       @click="handleAdd('GFBGYP')" type="primary" icon="plus">物资入库单</a-button>
<!--      <a-button   v-has="'yhp:add'"     @click="handleAdd('GFYHP')" type="primary" icon="plus" style="margin-left: 10px">新增易耗品物资入库单</a-button>-->
<!--      <a-button    v-has="'chwz:add'"  @click="handleAdd('GFCHWZ')" type="primary" icon="plus" style="margin-left: 10px">新增存货物资物资入库单</a-button>-->
      <div style="font-size: 16px;font-weight: 800;margin-top: 20px">-历史数据查询</div>

      <a-form layout="inline" @keyup.enter.native="searchQuery" style="margin-top: 10px">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
          <a-form-item label="单据编号">
            <a-input placeholder="请输入单据编号" v-model="queryParam.orderCode"></a-input>
          </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
<!--            <a-form-item label="入库部门">-->
<!--              <a-input placeholder="请输入入库=不 1" v-model="queryParam.putDepartment"></a-input>-->
<!--            </a-form-item>-->
<!--            <a-form-item label="入库部门" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--              <j-select-depart  v-model="queryParam.putDepartment"></j-select-depart>-->
<!--            </a-form-item>            v-show="toggleSearchStatus ? true : false "-->

            <a-form-item label="物资名称" :labelCol="labelCol" :wrapperCol="wrapperCol" >
              <j-search-select-tag type="list"  v-model="queryParam.assetId"
                                   :trigger-change="true"  dict="zcgl_asset_fixed,name,id" :disabled="disableSubmit"
                                   placeholder="物资名称"/>
            </a-form-item>

          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-cang-ku  v-model="queryParam.storage"></j-select-cang-ku>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>

              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>


          <a-col :xl="6" :lg="7" :md="8" :sm="24">


          </a-col>


        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">

<!--      <a-button type="primary" icon="download" @click="handleExportXls('物资入库表')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->
      <a-table
        :customRow="click"
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        @change="handleTableChange1">
<!--        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"-->
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--              <a  @click="modifyForm(record, '生效审批', 1)">-->
<!--              生效审批-->
<!--            </a>-->
<!--          <a @click="handleEdit(record)">编辑</a>-->

<!--          <a-divider type="vertical" />-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <zcgl-put-storage-modal-new   :disabled="disableSubmit" :assetTypeF="assetTypeF" id="print"  ref="modalForm"  :addFlag='addFlag'   :assetValue="queryParam.assetId"   @ok="modalFormOk"></zcgl-put-storage-modal-new>
    <!--流程表单-->
    <a-modal :title="lcModa.title" v-model="lcModa.visible" :footer="null" :maskClosable="false" width="80%">
      <component :disabled="lcModa.disabled" v-if="lcModa.visible" :is="lcModa.formComponent"
                 :processData="lcModa.processData" :isNew="lcModa.isNew"
                 @afterSubmit="processFormOk" @close="lcModa.visible=false, lcModa.disabled = false"></component>
    </a-modal>
<!--    <zcgl-put-asset-add></zcgl-put-asset-add>-->
  </a-card>
</template>

<script>
import store from '@/store'
  import { JeecgListMixin } from '@/mixins/componentMix'
  import ZcglPutStorageModalNew from './modules/ZcglPutStorageModalNew'
  import '@/assets/less/TableExpand.less'
  import { activitiMixin } from '@views/activiti/mixins/activitiMixin'
  import ZcglPutAssetAdd from '../activiti/form/ZcglPutAssetAdd'
  import JSelectDepart from '../../components/jeecgbiz/JSelectDepart'
  import JSelectAssets from '../../components/jeecgbiz/JSelectAssets'
  import JImageUpload from '../../components/jeecg/JImageUpload'
  import JSelectCangKu from '../../components/jeecgbiz/JSelectCangKu'
  import JSearchSelectTag from '../../components/dict/JSearchSelectTag'
  import pick from 'lodash.pick'
  import { getAction } from '../../api/manage'
  export default {
    name: "ZcglPutStorageList",
    mixins:[JeecgListMixin,activitiMixin],
    components: {
      ZcglPutAssetAdd,
      ZcglPutStorageModalNew,
      JSearchSelectTag, JSelectDepart, JSelectAssets,JImageUpload,JSelectCangKu
    },
    data () {
      return {
        assetTypeF:'',
        addFlag:false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 6 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        description: '物资入库表管理页面',
        // 表头
        disableSubmit:false,
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'入库单据编码',
            align:"center",
            dataIndex: 'orderCode'
          },
          {
            title:'入库部门',
            align:"center",
            dataIndex: 'putDepartment_dictText'
          },
          {
            title:'入库仓库',
            align:"center",
            dataIndex: 'storage_dictText'
          },
          {
            title:'制单人',
            align:"center",
            dataIndex: 'putUser_dictText'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime'
          },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   scopedSlots: { customRender: 'action' },
          // }
        ],
        url: {
          list: "/putstorage/zcglPutStorage/list",
          delete: "/putstorage/zcglPutStorage/delete",
          deleteBatch: "/putstorage/zcglPutStorage/deleteBatch",
          exportXlsUrl: "/putstorage/zcglPutStorage/exportXls",
          importExcelUrl: "putstorage/zcglPutStorage/importExcel",
        },

        dictOptions:{},
      }
    },
    created () {
      let usercode = store.getters.userInfo.id

      setTimeout(() => {
        if(usercode == '1199615897335095297'){
          this.searchQuery()
        }else{
          this.queryParam.putUser = usercode
          this.searchQuery()
        }


       },1)



    },

    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      //自己的方法
      searchReset() {



        let usercode = store.getters.userInfo.id
        if(usercode == '1199615897335095297'){
          this.loadData(1);

        }else{
          this.queryParam = { putUser: usercode }
          this.loadData(1);

        }
      },
      handleAdd(type) {
        this.addFlag = true
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
        this.$refs.modalForm.zcglPutStorageAssetsTable.dataSource = []
        this.$refs.modalForm.assetType = type
        this.assetTypeF = type


        getAction('/zcgl/assetFixed/list',{"assetType":type,"pageNo":1,"pageSize":3000}).then((res) => {
          if (res.success) {
            this.$refs.modalForm.assetList =  res.result.records

          }
        })

        // 过500毫秒调用
        setTimeout(() => {
          var data = {};


          if(type == 'CHWZ01'){
            data.storage = '1585440165014495234'

          }
          if(type == 'BGYP01'){
            data.storage = '1585440106449428481'

          }
          if(type == 'YHP01'){
            data.storage = '1585440063688499202'

          }

          this.$refs.modalForm.form.setFieldsValue(pick(data,'storage'))
        }, 111);


      },

      //双击事件
      onRowDoubleClick(record, index, event) {
        event.stopPropagation(); //阻止默认事件
      },
      click(record, index){
        return {
          on: {
            click: () => {

              this.addFlag = false
              this.handleEdit(record)
              this.$refs.modalForm.disableSubmit = true
              this.$refs.modalForm.assetType = ''

              this.$refs.modalForm.printData = record
              // getAction('/zcgl/assetFixed/list',{"assetType":type,"pageNo":1,"pageSize":3000}).then((res) => {
              //   if (res.success) {
              //     this.$refs.modalForm.assetList =  res.result.records
              //
              //   }
              // })


              this.$refs.modalForm.getAssetList();
            }
          },
        }
      },
      initDictConfig(){
      },
      modifyForm(r, name, type) {
        let tableData = {
          routeName: '@/views/activiti/form/ZcglPutAssetAdd',
          tableName: 'zcgl_put_storage',
          tableId: r.id,
          type:0
        }
        if (type == 1) {
          tableData.routeName = "@/views/activiti/form/ZcglPutAssetAdd"
        }
        this.processCreateCom(tableData, '发起资产入库' + name + '流程', r.processStatus)
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>